//
//  SuggestViewController.m
//  MassExpress
//
//  Created by 冉思路 on 15/10/10.
//  Copyright (c) 2015年 冉思路. All rights reserved.
//

#import "SuggestViewController.h"
#define Marin 10

@interface SuggestViewController ()<UITextViewDelegate>{
    UIAlertView *myAlert;
}

@end

@implementation SuggestViewController
//-(void)viewWillAppear:(BOOL)animated{
//    [APIManager sheZhiIP:RenRen_IP];
//}
//-(void)viewWillDisappear:(BOOL)animated{
//    [APIManager sheZhiIP:IP];
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor= LIGHTGRAYBACKCOLOR;
//    self.title=@"建议与反馈";
    [self drawNavWithTitle:@"建议与反馈"];
    [self drawBackButton];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quxiaojianpan)];
    [self.view addGestureRecognizer:tap];

    long content_height=KScreenHeight-STATUS_BAR_HEIGHT-NAVI_BAR_HEIGHT;
    long textView_height=2*content_height/7;
    
    self.automaticallyAdjustsScrollViewInsets=NO;
    self.textView=[[GCPlaceholderTextView alloc]initWithFrame:CGRectMake(Marin,64+Marin, KScreenWidth-2*Marin, textView_height)];
    [self.textView.layer setMasksToBounds:YES];
    [self.textView.layer setCornerRadius:5.0];
    self.textView.backgroundColor=[UIColor whiteColor];
    self.textView.placeholder = NSLocalizedString(@"请输入您的宝贵意见",);
    self.textView.text=@"";
    self.textView.returnKeyType = UIReturnKeyDone;
    self.textView.delegate = self;
    [self.view addSubview:self.textView];
    
    
    CGFloat btn_y=CGRectGetMaxY(self.textView.frame)+Marin;
    UIButton *commitOrder=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    commitOrder.frame=CGRectMake(Marin, btn_y, KScreenWidth-2*Marin, 34);
    commitOrder.backgroundColor = ZONGCOLOR;
    [commitOrder setTitle:@"提交" forState:UIControlStateNormal];
    [commitOrder setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [commitOrder addTarget:self action:@selector(sureApply) forControlEvents:UIControlEventTouchUpInside];
    [commitOrder.layer setMasksToBounds:YES];
    [commitOrder.layer setCornerRadius:5.0];
    [self.view addSubview:commitOrder];

    // Do any additional setup after loading the view.
    
    

}
-(void)quxiaojianpan{
    [self.textView resignFirstResponder];
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;

}
-(void)sureApply{
    if ([self jianCeLogin]) {
        if ([self.textView.text isEqualToString:@""]) {
            [self showAlert:@"请输入内容" orCode:10];
            
        }else{
            [self postSuggest];
            
        }

    }
    
}

#pragma mark 建议反馈
-(void)postSuggest{
    [self.textView resignFirstResponder];
    [TCUtils showLoadingWithView:self.view];
    
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc] init];
    [requestDic setObject:self.textView.text forKey:@"content"];
    [requestDic setObject:@"11" forKey:@"type"];
    
    if (![[self defaultLoadUserName]isEqualToString:@""]) {
        [requestDic setObject:[self defaultLoadUserName] forKey:@"username"];
    }
    
//    [NetWorking jieKouQingQiu:SYS_YIJIANFANKUI And:requestDic anBlock:^(NSDictionary *dic, NSError *error) {
//        if (!error) {
//            [self showAlert:[dic objectForKey:Msg] orCode:[[dic objectForKey:Code] intValue]];
//        }
//    }];
}
-(void)showAlert:(NSString *)str orCode:(int)code{
    myAlert = [[UIAlertView alloc] initWithTitle:nil message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [myAlert show];
    [self performSelector:@selector(diss) withObject:nil afterDelay:1.5];
    if (code == 200) {
        [self performSelector:@selector(popVC) withObject:nil afterDelay:1.6];
    }
}
-(void)diss{
    [myAlert dismissWithClickedButtonIndex:0 animated:YES];
}
-(void)popVC{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
